﻿@model RefundOrderModel
@{
    ViewBag.Title = "退款详情";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new RefundOrderModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    Dictionary<string, string> labelDicTypeName = ReleaseBiz.GetLabelTypeNameDic();
}

    <form id="S_Form" method="post" class="definewidth m20" enctype="multipart/form-data">
        <table class="table table-bordered table-hover definewidth m10">
            <tr>
                <td colspan="2" style="width:50%">
                    <h5>
                        @ViewBag.Title
                    </h5>
                    <input type="hidden" value="@viewModel.refundorder.order_id" name="refund_order_id" />
                </td>
            </tr>
            <tr>
                <td width="10%" class="tableleft">销售订单</td>
                <td>
                    <div>订单号： @viewModel.view_order.order_NO</div>
                    <div>订单总金额：@viewModel.view_order.total_money</div>
                </td>
                <td class="tableleft">下单用户</td>
                <td>
                    <div>手机号：@viewModel.view_order.account_mobile</div>
                    <div>会员名称：@viewModel.view_order.member_name</div>
                    <div>代购编号：@viewModel.view_order.replace_buyer_NO</div>
                </td>
            </tr>
            <tr>
                <td width="10%" class="tableleft">退款订单号</td>
                <td>
                    @viewModel.refundorder.order_no
                </td>

                <td class="tableleft">申请人</td>
                <td>
                    @viewModel.refundorder.apply_user  申请时间：@viewModel.refundorder.create_time
                </td>
            </tr>
            <tr>
                <td width="10%" class="tableleft">退款金额</td>
                <td>
                    @viewModel.refundorder.refund_amt
                </td>

                <td class="tableleft">退款状态</td>
                <td>
                    @(MyEnumHelper.GetEnumItemDescription<RefundSatus>(viewModel.refundorder.status.Value))

                    @if (viewModel.refundorder.status.Value == 0)
                    {
                        if (viewModel.refundorder.tow_audit_status == 0)
                        {
                            if (viewModel.refundorder.first_audit_status == 0)
                            {
                                @:<a href="javascript:void(0);" data-id="@viewModel.refundorder.order_id" class="btnedit">退款初审</a>
                            }
                            else if (viewModel.refundorder.first_audit_status == 1)
                            {
                                @:<a href="javascript:void(0);" data-id="@viewModel.refundorder.order_id" class="btnedit">退款复审</a>
                            }
                        }
                    }

                </td>
            </tr>
            <tr>
                <td width="10%" class="tableleft">退款原因</td>
                <td colspan="3">
                    @viewModel.refundorder.reason
                </td>
            </tr>
            <tr>
                <td width="10%" class="tableleft">初审信息</td>
                <td>
                    <div>审核人：@viewModel.refundorder.first_audit_user</div>
                    <div>审核时间：@viewModel.refundorder.first_audit_time</div>
                    <div>审核状态：@(MyEnumHelper.GetEnumItemDescription<AuditStatus>(viewModel.refundorder.first_audit_status.Value))</div>
                    <div>驳回原因：@viewModel.refundorder.first_audit_remark</div>
                </td>

                <td class="tableleft">复审信息</td>
                <td>
                    <div>审核人：@viewModel.refundorder.tow_audit_user</div>
                    <div>审核时间：@viewModel.refundorder.tow_audit_time</div>
                    <div>审核状态：@(MyEnumHelper.GetEnumItemDescription<AuditStatus>(viewModel.refundorder.tow_audit_status.Value))</div>
                    <div>驳回原因：@viewModel.refundorder.two_audit_remark</div>
                </td>
            </tr>
            <tr>
                <td width="10%" class="tableleft">退款状态</td>
                <td colspan="1">
                    @(MyEnumHelper.GetEnumItemDescription<RefundSatus>(viewModel.refundorder.status))
                </td>
                <td width="10%" class="tableleft">退款信息</td>
                <td colspan="1" style="white-space: pre-line;">
                    @viewModel.refundorder.transfer_remark
                </td>
            </tr>
        </table>
        <h5>商品列表</h5>

        <table class="table table-bordered table-hover definewidth m10">
            <thead>
                <tr>
                    <th style="width:70px">图片</th>
                    <th>料号</th>
                    <th>品牌</th>
                    <th>分类</th>
                    <th>供应商</th>
                    <th>板块</th>
                    <th>库存价格</th>
                    <th>订购数量</th>
                    <th>单位</th>
                    <th>供货单价</th>
                    <th>佣金比例</th>
                    <th>销售单价</th>
                    <th>订单总价</th>
                    <th>币种</th>
                    <th>佣金金额</th>
                    <th></th>
                </tr>
            </thead>
            @if (viewModel.orderGoods != null && viewModel.orderGoods.Count != 0)
            {
                int index = 0;
                foreach (var orderGoods in viewModel.orderGoods)
                {
                    var m = orderGoods.views_Goods;
                    var goodsdetail = orderGoods.aDZ_OrderDetails;
                    index++;
                    <tr class="@HtmlPagerHelper.TrClass(index)">
                        <td>
                            @{
                                var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
                                foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                                {
                                    <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                                }
                            }
                        </td>
                        <td>@m.MPN</td>
                        <td>@m.brand_name</td>
                        <td>@m.category_name</td>
                        <td>@m.supplier_name</td>
                        <td>
                            <div>@labelDicTypeName[m.label_type.ToString()]</div>
                        </td>
                        <td>@m.price</td>
                        <td>@goodsdetail.amount</td>
                        <td>@m.goods_unit</td>

                        <td>@(m.supply_price == null ? "-" : m.supply_price.Value.ToString("f5"))</td>
                        <td>@(m.supply_price == null ? "-" : ((goodsdetail.sell_price - m.supply_price) / goodsdetail.sell_price).Value.ToString("f5"))</td>

                        <td>@((goodsdetail.sell_price).ToString("f5"))</td>

                        <td>@goodsdetail.total_money.Value.ToString("f2")</td>
                        <td>
                            @switch (m.currency_type)
                            {
                                case 0:
                                    @:<div class="">人民币</div>
                                    break;
                                case 1:
                                    @:<div class="red">美金</div>
                                    break;
                            }
                        </td>
                        <td>@(m.supply_price == null ? "-" : ((goodsdetail.sell_price - m.supply_price) * goodsdetail.amount).Value.ToString("f5"))</td>
                        <td>
                            <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
                        </td>
                    </tr>
                }
            }
        </table>
        <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>

    </form>


<div id="markDiv" class="hidden">
    <form id="form" class="form-horizontal">
        <input type="hidden" id="txtorder_id" />
        <div id="divMark" style="display:none;" class="row">
            <div class="tips tips-small tips-warning span2">
                <span class="x-icon x-icon-small x-icon-error"><i class="icon icon-white icon-bell"></i></span>
                <div class="tips-content">
                    审核驳回
                </div>
            </div>
            <div class="control-group span12" style="margin-top:10px;">
                <hr style="border:none;border-top:1px ridge #000000;" />
            </div>
            <div class="control-group span12">
                <label class="control-label">
                    驳回原因
                </label>
                <div class="controls control-row4">
                    <textarea id="txtreason" class="input-large" data-rules="{required : true}"></textarea>
                </div>
            </div>
            <div class="control-group">
                <a class="button button-success" style="float:right;margin: -30px 40px;" onclick="Reject()">提交</a>
            </div>
        </div>
    </form>
</div>

<script>
    reloadHandler = function () {
        window.location.reload();
    }
    var remark = "";
    var url = "";
    @{
        if (viewModel.refundorder.first_audit_status == 0)
        {
            @:remark = "退款初审";
            @:url = "@Url.Action("firstaudit", "ordermaster")";
                        }
        else if (viewModel.refundorder.first_audit_status == 1)
        {
            @:remark = "退款复审";
            @:url = "@Url.Action("twoaudit", "ordermaster")";
        }
    }


    BUI.use(['bui/form', 'bui/overlay'], function (Form, overlay) {
        new Form.Form({
            srcNode: '#S_Form'
        }).render();

            //弹出框
            var dialog = new overlay.Dialog({
                title: remark,
                width: 500,
                height: 410,
                //配置DOM容器的编号
                contentId: 'markDiv',
                mask: false,
                buttons: [
                 {
                     text: '审核通过',
                         elCls: 'button button-success',
                         handler: function () {

                             url = url;
            parameter = {
                             order_id: $('#txtorder_id').val(),
                             status: 1,
                             msg: ""
                         };
                         $.post(url, parameter, function (result) {
            ShowActionResult(result, reloadHandler);
        });
                         $('.bui-ext-mask').hide();
                         $('#txtreason').html('');
                         this.close();
                     }
                 },{
                     text: '审核驳回',
                     elCls: 'button button-warning',
                     handler: function () {
            var bhhtml = $(".bui-stdmod-body").eq(0).clone();
                         $(".bui-stdmod-body").eq(0).remove();
                         $(".bui-stdmod-footer").eq(0).after(bhhtml);

                         $(".bui-stdmod-body").eq(0).fadeIn();
                         $("#divMark").fadeIn();
        }
                 }
            ],
            success: function () {
            this.close();
        }
        });

        $('.btnedit').on('click', function () {
            $("#divMark").hide();
            $('.bui-ext-mask').show();
            id = $(this).attr("data-id");
            msg = $(this).attr("data-msg");
            $('#txtorder_id').val(id);
            $('#txtreason').val(msg);
            dialog.show();
            $("#form").parent().hide();
            //弹出层关闭遮罩层
            $('.bui-ext-close').on('click', function () {
                $('#txtreason').html('');
                $('.bui-ext-mask').hide();
            });
        });
    });

    function Reject() {
        url = url;
        parameter = {
        order_id: $('#txtorder_id').val(),
        status: 2,
        msg: $('#txtreason').val()
        };
        $.post(url, parameter, function (result) {
            ShowActionResult(result, reloadHandler);
        });
        $('.bui-ext-mask').hide();
        $('#txtreason').html('');
        this.close();
    };
</script>
